<?php

namespace iBrand\Store\Backend\Console;

use iBrand\Store\Backend\Model\Models;
use iBrand\Store\Backend\Model\Spec;
use Illuminate\Console\Command;
use DB;

class SpecCommand extends Command
{

    protected $signature = 'goods_spec:factory';

    protected $description = 'create specs default data.';

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {

        return $this->generateSpecData();
    }

    private function generateSpecData()
    {

        if (!Spec::where('name', '尺寸')->first()) {
            $spec = Spec::create(['name' => '尺寸', 'type' => 1]);
            DB::table(config('ibrand.app.database.prefix', 'ibrand_') . 'base_specs_value')->insert([
                ['spec_id' => $spec->id, 'name' => 'S'],
                ['spec_id' => $spec->id, 'name' => 'M'],
                ['spec_id' => $spec->id, 'name' => 'L'],
            ]);
        }

        if (!Spec::where('type', '2')->first()) {
            Spec::create(['name' => '颜色', 'type' => 2]);
            DB::table(config('ibrand.app.database.prefix', 'ibrand_') . 'base_specs_value')->insert([
                ['spec_id' => 2, 'name' => '黑色', 'rgb' => '000000', 'color' => '黑色'],
                ['spec_id' => 2, 'name' => '橘红色', 'rgb' => 'ff7500', 'color' => '红色'],
                ['spec_id' => 2, 'name' => '玫红色', 'rgb' => 'df1b76', 'color' => '红色'],
                ['spec_id' => 2, 'name' => '粉红色', 'rgb' => 'ffb6c1', 'color' => '红色'],
                ['spec_id' => 2, 'name' => '红色', 'rgb' => 'ff0000', 'color' => '红色'],
                ['spec_id' => 2, 'name' => '藕色', 'rgb' => 'eed0d8', 'color' => '红色'],
                ['spec_id' => 2, 'name' => '西瓜红', 'rgb' => 'f05654', 'color' => '红色'],
                ['spec_id' => 2, 'name' => '酒红色', 'rgb' => '990000', 'color' => '红色'],
                ['spec_id' => 2, 'name' => '军绿色', 'rgb' => '5d762a', 'color' => '绿色'],
                ['spec_id' => 2, 'name' => '浅绿色', 'rgb' => '98fb98', 'color' => '绿色'],
                ['spec_id' => 2, 'name' => '绿色', 'rgb' => '008000', 'color' => '绿色'],
                ['spec_id' => 2, 'name' => '翠绿色', 'rgb' => '0aa344', 'color' => '绿色'],
                ['spec_id' => 2, 'name' => '青色', 'rgb' => '00e09e', 'color' => '绿色'],
                ['spec_id' => 2, 'name' => '天蓝色', 'rgb' => '44cef6', 'color' => '蓝色'],
                ['spec_id' => 2, 'name' => '孔雀蓝', 'rgb' => '00a4c5', 'color' => '蓝色'],
                ['spec_id' => 2, 'name' => '宝蓝色', 'rgb' => '4b5cc4', 'color' => '蓝色'],
                ['spec_id' => 2, 'name' => '浅蓝色', 'rgb' => 'd2f0f4', 'color' => '蓝色'],
                ['spec_id' => 2, 'name' => '深蓝色', 'rgb' => '041690', 'color' => '蓝色'],
                ['spec_id' => 2, 'name' => '湖蓝色', 'rgb' => '30dff3', 'color' => '蓝色'],
                ['spec_id' => 2, 'name' => '蓝色', 'rgb' => '0000fe', 'color' => '蓝色'],
                ['spec_id' => 2, 'name' => '藏青色', 'rgb' => '2e4e7e', 'color' => '蓝色'],
                ['spec_id' => 2, 'name' => '浅紫色', 'rgb' => 'ede0e6', 'color' => '紫色'],
                ['spec_id' => 2, 'name' => '深紫色', 'rgb' => '430653', 'color' => '紫色'],
                ['spec_id' => 2, 'name' => '紫红色', 'rgb' => '8b0062', 'color' => '紫色'],
                ['spec_id' => 2, 'name' => '紫罗兰', 'rgb' => 'b7ace4', 'color' => '紫色'],
                ['spec_id' => 2, 'name' => '紫色', 'rgb' => '800080', 'color' => '紫色'],
                ['spec_id' => 2, 'name' => '咖啡色', 'rgb' => '603912', 'color' => '棕色'],
                ['spec_id' => 2, 'name' => '巧克力色', 'rgb' => 'd2691e', 'color' => '棕色'],
                ['spec_id' => 2, 'name' => '栗色', 'rgb' => '60281e', 'color' => '棕色'],
                ['spec_id' => 2, 'name' => '浅棕色', 'rgb' => 'b35c44', 'color' => '棕色'],
                ['spec_id' => 2, 'name' => '深卡其布色', 'rgb' => 'bdb76b', 'color' => '棕色'],
                ['spec_id' => 2, 'name' => '深棕色', 'rgb' => '7c4b00', 'color' => '棕色'],
                ['spec_id' => 2, 'name' => '褐色', 'rgb' => '855b00', 'color' => '棕色'],
                ['spec_id' => 2, 'name' => '驼色', 'rgb' => 'a88462', 'color' => '棕色'],
                ['spec_id' => 2, 'name' => '浅灰色', 'rgb' => 'e4e4e4', 'color' => '灰色'],
                ['spec_id' => 2, 'name' => '深灰色', 'rgb' => '666666', 'color' => '灰色'],
                ['spec_id' => 2, 'name' => '灰色', 'rgb' => '808080', 'color' => '灰色'],
                ['spec_id' => 2, 'name' => '银色', 'rgb' => 'c0c0c0', 'color' => '灰色'],
            ]);
        }

        if (Models::all()->count() == 0) {
            Models::create([
                'name' => '服装',
                'spec_ids' => [1,2]
            ]);
        }


    }

}